package com.clement.observe;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Clement on 2017/2/28.
 */
@Component
public class ObserverPatternDemo {

    private Subject subject;
    private HexObserver hexObserver;
    private OctalObserver octalObserver;
    private BinaryObserver binaryObserver;

    @Autowired
    public void setSubject(Subject subject) {
        this.subject = subject;
    }

    @Autowired
    public ObserverPatternDemo(HexObserver hexObserver, OctalObserver octalObserver, BinaryObserver binaryObserver) {
        this.binaryObserver = binaryObserver;
        this.octalObserver = octalObserver;
        this.hexObserver = hexObserver;
    }


    public void observe() {
        System.out.println("First state change: 15");
        subject.setState(15);
        System.out.println("First state change: 10");
        subject.setState(10);
    }
}
